package com.students.service.impl;

import com.students.utils.AdminUtil;
import com.students.pojo.Menu;
import com.students.mapper.MenuMapper;
import com.students.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author caohanqing
 * @since 2022-04-06
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

    @Autowired(required = false)
    private MenuMapper menuMapper;
    @Override
    //通过用户id查询菜单列表
    public List<Menu> getMenusByAdminId() {
        //这个为未建立工具类的情况下
//        return menuMapper.getMenusByAdminId(
//                ((Admins) SecurityContextHolder.getContext()
//                .getAuthentication()
//                .getPrincipal())
//                .getId()
//        );

        return menuMapper.getMenusByAdminId(
                AdminUtil.getCurrentAdmin().getId());
    }

    @Override
    //根据角色获取菜单列表
    public List<Menu> getMenusWithRole() {
        return menuMapper.getMenusWithRole();
    }

    //获取所有菜单
    @Override
    public List<Menu> getAllMenus() {
        return menuMapper.getAllMenus();
    }
}
